package
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	
	public class Menu extends Sprite
	{
		
		public function Menu(stage:Stage, items:Array)
		{
			var i:int;
			for(i = 0; i < items.length; i++){
				items[i] = new MenuBox(this, items[i].title, items[i].onClick, 0, 0);
				items[i].y = i != 0 ? items[i-1].y + items[i-1].height : 0;
				items[i].centerVertically(stage.stageWidth);
				this.addChild(items[i]);
				items[i].addEventListener(MouseEvent.CLICK, items[i].onClick);
			}
			
			centerHorizontally(stage.stageHeight);
		}
		
		public function center(w:int, h:int):void{
			centerVertically(w);
			centerHorizontally(h);
		}
		
		public function centerVertically(w:int):void{
			this.x = (w - this.width) / 2;
		}
		
		public function centerHorizontally(h:int):void{
			this.y = (h - this.height) / 2;
		}
	}
}